/**
*      author: Y_Yao
*      created: 2024-10-21 19:09:02
**/

#include<bits/stdc++.h>

using namespace std;
#define int LL
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 7;
int a[N],l[N],r[N],diff[N],num[N],sum[N];
int n,m;

bool check(int mid)
{
    memset(diff,0,sizeof(diff));
    for(int i = 1;i <= mid;i++)
    {
        diff[l[i]] += num[i];
        if(r[i] + 1 <= n) diff[r[i] + 1] -= num[i];
    }

    for(int i = 1;i <= n;i++)
    {
        sum[i] = sum[i-1] + diff[i];
        if(sum[i] > a[i]) return false;
    }
    return true;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    for(int i = 1;i <= m;i++)
    {
        cin >> num[i] >> l[i] >> r[i];
    }
    if(check(m))
    {
        cout << 0 << endl;
        return 0;
    }
    int l = 1,r = m;
    while(l < r)
    {
        int mid = (l + r) >> 1;
        if(check(mid)) l = mid + 1;
        else r = mid;
    }
    cout << -1 << endl;
    cout << l;

    return 0;
}